<?php
/**
 * NOTICE OF LICENSE
 *
 * This source file is subject to the  Academic Free License (AFL 3.0)
 * that is available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to support@zprofess.com so we can send you a copy immediately.
 *
 * @category   	Prestashop module
 * @package		Help Desk
 * @version 	1.0
 * @author 		Rukan Hitokiri <rukanhitokiri@zprofess.com>
 * @copyright   Copyright (c) 2012 ZPROFESS. (http://zprofess.com)
 * @license    	http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

require_once ('Zadmindepartmentcontent.php');
require_once(dirname(__FILE__).'/lib/zprofess/ZhelpdeskadminTab.php');

class Zadmindepartment extends ZhelpdeskadminTab {

	/** @var object new list department */
    private $adminDepartment;
    /** @var string name table department	*/
    private $tableName = 'zhelpdesk_department';

    /**
     * Sole constructor
    */ 
    public function __construct() {
        $this->adminDepartment = new Zadmindepartmentcontent();
        $this->table = array(
            $this->table,
            'employee');
        parent::__construct();
        $this->adminDepartment->token = $this->token;
    }
	
    /**
	 * @see AdminTabs->postProcess();
	 * 
	 * Manage page processing
	 *
	 * @global string $currentIndex Current URL in order to keep current Tab
	 */
    public function postProcess() {
        $this->adminDepartment->postProcess();
    }
	
    /**
     * @see admintab->viewAccess()
     * 
	 * Check rights to view the current tab
	 *
	 * @return boolean
	 */
    public function viewAccess($disable = false) {
        $result = parent::viewAccess($disable);
        $this->adminDepartment->tabAccess = $this->tabAccess;
        return $result;
    }

    /**
     * @seeadmintab->display()
     * 
	 * Manage page display (form, list...)
	 *
	 * @global string $currentIndex Current URL in order to keep current Tab
	 */
    public function display() {
        global $currentIndex;

        if (((Tools::isSubmit('submitAdd' . $this->tableName)
                OR Tools::isSubmit('submitAdd' . $this->tableName . 'AndStay'))
                AND sizeof($this->adminDepartment->_errors))
                OR isset($_GET['update' . $this->tableName])
                OR isset($_GET['add' . $this->tableName])
        ) {
        	if (isset($_GET['id_'.$this->tableName]))
        		echo ' <h3>'.$this->l('Update Department').'</h3>';
        	else
        		echo ' <h3>'.$this->l('Add Department').'</h3>';
            $this->adminDepartment->displayForm($this->token);
            echo '<br /><br /><a href="' . $currentIndex . '&token=' . $this->token . '"><img src="../img/admin/arrow2.gif" /> ' . $this->l('Back to list') . '</a><br />';
        } else {
            $this->adminDepartment->display($this->token);
        }
    }

    /**
	 * Display errors
	 */
    public function displayErrors(){
        parent::displayErrors();
        $this->adminDepartment->displayErrors();
    }

}
?>